import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class P54 {
	private static int getNum(String num) {
		if ("T".equals(num)) {
			return 10;
		} else if ("J".equals(num)) {
			return 11;
		} else if ("Q".equals(num)) {
			return 12;
		} else if ("K".equals(num)) {
			return 13;
		} else if ("A".equals(num)) {
			return 14;
		} else {	
			return Integer.parseInt(num);
		}
	}
	
	private static Map<String, List<Integer>> getMap(String line) {
		String[] values = line.split(" ");
		
		Map<String, List<Integer>> map = new HashMap<String, List<Integer>>();

		for (int i = 0; i < values.length; i++) {
			String suit = null;
			Integer x = null;
	
			String value = values[i];
			
			if (value.length() == 3) {
				suit = value.substring(2);
				x = Integer.parseInt(value.substring(0, 2));
			} else if (value.length() == 2) {
				suit = value.substring(1);
				x = getNum(value.substring(0, 1));
			}
	
			List<Integer> list = map.get(suit);
			if (list == null) {
				list = new ArrayList<Integer>();
				map.put(suit, list);
			}
			list.add(x);
		}	
		return map;
	}

	private static int royalFush(Map<String, List<Integer>> map) {
		if (map.size() == 1) {
			List<Integer> list = map.get(map.keySet().toArray(new String[0])[0]);
			if (list.contains(10) && list.contains(11) && list.contains(12)
					&& list.contains(13) && list.contains(14)) {
				return 1;
			}
		}
		return 0;
	}
	
	private static int straightFlush(Map<String, List<Integer>> map) {
		if (map.size() == 1) {
			List<Integer> list = map.get(map.keySet().toArray(new String[0])[0]);
			int min = Integer.MAX_VALUE;
			for (Integer i : list) {
				if (min > i) {
					min = i;
				}
			}
			
			boolean isConsecutive = true;
			for (int i = 0; i < list.size(); i++) {
				if (!list.contains(min + i)) {
					isConsecutive = false;
				}
			}
			
			if (isConsecutive) {
				return min + list.size() - 1;
			}
		}
		return 0;
	}

	private static int[] fourKind(Map<String, List<Integer>> map) {
		Map<Integer, Integer> m = getValueMap(map);
		
		if (m.size() == 2) {
			Integer[] value = m.keySet().toArray(new Integer[0]);
			int[] x = new int[2];
			int count = 0;
			for (int i= 0; i < value.length; i++) {
				if (m.get(value[i]) == 4) {
					x[0] = value[i];
					count++;
				} else if (m.get(value[i]) == 1) {
					x[1] = value[i];
					count++;
				}
			}
			
			if (count == 2) {
				return x;
			}
		}
		
		return null;
		
	}
	
	private static int[] fullHouse(Map<String, List<Integer>> map) {
		Map<Integer, Integer> m = getValueMap(map);
		
		if (m.size() == 2) {
			Integer[] value = m.keySet().toArray(new Integer[0]);
			int[] x = new int[2];
			int count = 0;
			for (int i= 0; i < value.length; i++) {
				if (m.get(value[i]) == 3) {
					x[0] = value[i];
					count++;
				} else if (m.get(value[i]) == 2) {
					x[1] = value[i];
					count++;
				}
			}
			
			if (count == 2) {
				return x;
			}
		}
		
		return null;
		
	}
	
	private static int flush(Map<String, List<Integer>> map) {
		int max = 0;
		if (map.size() == 1) {			
			List<Integer> list = map.get(map.keySet().toArray(new String[0])[0]);
			for (Integer i : list) {
				if (max < i) {
					max = i;
				}
			}
		} 
		return max;
	}
	
	private static Map<Integer, Integer> getValueMap(Map<String, List<Integer>> map) {
		Iterator<List<Integer>> iterator =  map.values().iterator();
		
		Map<Integer, Integer> m = new HashMap<Integer, Integer>();		
		while (iterator.hasNext()) {
			List<Integer> list = iterator.next();
			
			for (Integer i: list) {
				Integer count = m.get(i);
				if (count == null) {
					count = 0;
				}
				count++;
				m.put(i, count);			
			}
		}	
		return m;
	}
	
	private static int straight(Map<String, List<Integer>> map) {
		
		Map<Integer, Integer> m = getValueMap(map);
		Integer[] v = m.keySet().toArray(new Integer[0]);
		
		int max = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < v.length; i++) {
			Integer x = v[i];
			
			if (x > max) {
				max = x;
			}
			
			if (x < min) {
				min = x;
			}
		}
		
		if (v.length == 5 && max - min == 4) {
			return max;
		}
				
		return 0;
	}
	
	private static int[] threeKind(Map<String, List<Integer>> map) {
		Map<Integer, Integer> m = getValueMap(map);	
		//System.out.println(m);
		Integer[] value = m.keySet().toArray(new Integer[0]);
		
		
		int[] x = new int[2];		
		int count = 0;
		for (int i= 0; i < value.length; i++) {
			if (m.get(value[i]) == 3) {
				x[0] = value[i];
				count++;
			} 
			
			if (m.get(value[i]) == 1) {
				if (x[1] < value[i]) {
					x[1] = value[i];
				}
			}
		}
		
		if (count == 1 && value.length == 3) {
			return x;
		}
		
		return null;
		
	}
	
	private static int[] twoPair(Map<String, List<Integer>> map) {
		Map<Integer, Integer> m = getValueMap(map);
//		System.out.println(">>>" + map);
//		System.out.println(">>>" + m);
		Integer[] value = m.keySet().toArray(new Integer[0]);
		
		int count = 0;
		int max = 0;
		int min = Integer.MAX_VALUE;
		
		int[] x = new int[3];
		
		for (int i= 0; i < value.length; i++) {
			if (m.get(value[i]) == 2) {
				count++;
				
				if (max < value[i]) {
					max = value[i];
				}
				
				if (min > value[i]) {
					min = value[i];
				}
			} else {
				x[2] = value[i];
			}
		}
		
		if (count == 2) {
			x[0] = max;
			x[1] = min;
			return x;
		}
		return null;
		
	}
	
	private static int[] onePair(Map<String, List<Integer>> map) {
		Map<Integer, Integer> m = getValueMap(map);	
		Integer[] value = m.keySet().toArray(new Integer[0]);
		
		int count = 0;		
		int[] x = new int[2];
		for (int i= 0; i < value.length; i++) {
			if (m.get(value[i]) == 2) {
				count++;
				x[0] = value[i];
			} else {
				if (x[1] < value[i]) {
					x[1] = value[i];
				}
			}
		}
		
		if (count == 1) {
			return x;
		}
		return null;
		
	}
	
	private static int highCard(Map<String, List<Integer>> map) {
		Map<Integer, Integer> m = getValueMap(map);	
		Integer[] value = m.keySet().toArray(new Integer[0]);
		
		if (m.size() == 5) {
			int max = 0;
			
			for (int i = 0; i < value.length; i++) {
				if (max < value[i]) {
					max = value[i];
				}
			}
			
			return max;
		}
		return 0;
		
	}
	
	public static String compare(String a, String b) {
		int[] x = getValue(a);
		int[] y = getValue(a);
		
		for (int i = 0; i < x.length; i++) {
			if (x[i] > y[i]) {
				return "left";
			} 
			
			if (x[i] < y[i]) {
				return "right";
			}			
		}
		
		return null;
	}
	
	public static String compare(String line) {		
		int[] x = getValue(line.substring(0, 14));
		System.out.println(Arrays.toString(x));
		int[] y = getValue(line.substring(15));
		System.out.println(Arrays.toString(y));
		
		for (int i = 0; i < x.length; i++) {
			if (x[i] > y[i]) {
				return "left";
			} 
			
			if (x[i] < y[i]) {
				return "right";
			}			
		}
		
		return null;
	}
	
	public static int[] getValue(String line) {
		int[] result = new int[10];
		
		Map<String, List<Integer>> map = getMap(line);
		
		result[0] = royalFush(map);
		if (result[0] > 0) {
			return result;
		}
		
		result[1] = straightFlush(map);
		if (result[1] > 0) {
			return result;
		}
		
		int[] x = fourKind(map);
		if (x != null) {
			result[2] = x[0];
			result[9] = x[1];
			return result;
		}
		
		x = fullHouse(map);
		if (x != null) {
			result[3] = x[0];
			result[8] = x[1];
			return result;
		}
	
		result[4] = flush(map);
		if (result[4] > 0) {
			return result;
		}
		
		result[5] = straight(map);
		if (result[5] > 0) {
			return result;
		}
		
		x = threeKind(map);
		if (x != null) {
			System.out.println("threeKind");
			result[6] = x[0];
			result[9] = x[1];
			return result;
		}
		
		x = twoPair(map);
		if (x != null) {
			System.out.println("two");
			result[7] = x[0];
			result[8] = x[1];
			result[9] = x[2];
			return result;
		}
		
		x = onePair(map);
		if (x != null) {
			System.out.println("one");
			result[8] = x[0];
			result[9] = x[1];
			return result;
		}
		
		result[9] = highCard(map);
		System.out.println("high");
		return result;
	}
	
	// 385
	public static void main(String[] args) throws Exception {		
//		System.out.println(royalFush(getMap("10D JD QD KD AD")));
//		System.out.println(straightFlush(getMap("9D 10D JD QD KD")));
//		System.out.println(fourKind(getMap("10D 10H 10S 10C AD")));
//		System.out.println(fullHouse(getMap("10D 10H 10S AC AD")));
//		System.out.println(flush(getMap("10D 2D AD 3D 9D")));
//		System.out.println(straight(getMap("2D 3D 4D 5H 6S")));
//		System.out.println(threeKind(getMap("2D 2H 2C 4H 5S")));
//		System.out.println(Arrays.toString(twoPair(getMap("AS KH 4C AD 4S"))));
//		System.out.println(onePair(getMap("2D 2H 4C 3H 5S")));
//		System.out.println(highCard(getMap("2D 3H 4C 7H 5S")));
//		
//		System.out.println();
//		
//		System.out.println(Arrays.toString(getValue("10D JD QD KD AD")));
//		System.out.println(Arrays.toString(getValue("9D 10D JD QD KD")));
//		System.out.println(Arrays.toString(getValue("10D 10H 10S 10C AD")));
//		System.out.println(Arrays.toString(getValue("10D 10H 10S AC AD")));
//		System.out.println(Arrays.toString(getValue("10D 2D AD 3D 9D")));
//		System.out.println(Arrays.toString(getValue("2D 3D 4D 5H 6S")));
//		System.out.println(Arrays.toString(getValue("2D 2H 2C 4H 5S")));
//		System.out.println(Arrays.toString(getValue("2D 2H 3C 3H 5S")));
//		System.out.println(Arrays.toString(getValue("2D 2H 4C 3H 5S")));
//		System.out.println(Arrays.toString(getValue("2D 3H 4C 7H 5S")));
//		
//		System.out.println(compare("5H 5C 6S 7S KD 2C 3S 8S 8D TD"));
//		System.out.println(compare("5D 8C 9S JS AC 2C 5C 7D 8S QH"));
//		System.out.println(compare("2D 9C AS AH AC 3D 6D 7D TD QD"));
//		System.out.println(compare("4D 6S 9H QH QC 3D 6D 7H QD QS"));
//		System.out.println(compare("2H 2D 4C 4D 4S 3C 3D 3S 9S 9D"));
//		System.out.println(compare("7C 5H KC QH JD AS KH 4C AD 4S"));
		
		
		BufferedReader reader = new BufferedReader(new FileReader(new File("P54.txt")));
		String line = null;
		
		int leftCount = 0;
		int rightCount = 0;
		
		int x = 0;
		while ((line = reader.readLine()) != null) {
			//System.out.println(compare(line));
			if ("left".equals(compare(line))) {
				leftCount++;
			} else if ("right".equals(compare(line))) {
				rightCount++;
			} else {
				System.out.println(line);
			}
			x++;
		}
		System.out.println(x);
		reader.close();
		System.out.println(leftCount);
		System.out.println(rightCount);
		
	}
}
